<?php

/*
 * This makes it possible to load the object from the PHPX Generator.
 * The class itself must implement the Render function in order to be able to render from PHPX
 * 
 * @author Martien de Jong
 * @version 1.0
 */

class PHPXLoadableTrait
{
	/*
	 * Creates the collection for child items, and initializes the template trait, which enables templating
	 */
	public function InitPHPX( )
	{
		$this->Children = new Collection( );
		$this->TraitOwner->Traits[] = new TemplateTrait( );
		$this->TraitOwner->InitTraits( );
	}
	
	/*
	 * Renders the content of the PHPX object
	 */
	public function RenderContent( )
	{
		$this->RenderChildren( );
		$this->RenderXML( );
		$this->RenderText( );
	}
	
	/*
	 * Renders child PHPX controls
	 */
	public function RenderChildren( )
	{
		if( $this->Children->Count( ) > 0 )
		{
			$this->Children->Render( );
		}
	}
	
	/*
	 * Renders the inner XML (or XHTML) nodes
	 */
	public function RenderXML( )
	{
		if( is_object( $this->TraitOwner->XML ) )
		{
			$Children = $this->TraitOwner->XML->children( );
			foreach( $Children as $Child )
			{
				print $Child->asXML( );
			}
		}
	}
	
	/*
	 * Renders the inner text
	 */
	public function RenderText( )
	{
		print $this->TraitOwner->XML;
	}
}